package com.hjl.sr.remoting;

import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;

import com.hjl.sr.security.token.TokenGenerator;
import com.hjl.sr.security.token.TokenGeneratorImpl;
import com.hjl.sr.security.token.TokenService;
import com.hjl.sr.security.token.TokenServiceImpl;
import com.hjl.sr.security.token.store.TokenStoreService;
import com.hjl.sr.util.TokenStoreServiceHolder;

public class TokenSeviceProvider extends HttpInvokerServiceExporter {

	private TokenStoreService tokenStoreService;
	
	private TokenGenerator tokenGenerator;
	
	@Override
	public void afterPropertiesSet() {
		this.setServiceInterface(TokenService.class);
		this.setService(new TokenServiceImpl(getTokenStoreService(), getTokenGenerator()));		
		super.afterPropertiesSet();
	}

	public void setTokenStoreService(TokenStoreService tokenStoreService) {
		this.tokenStoreService = tokenStoreService;
	}

	public void setTokenGenerator(TokenGenerator tokenGenerator) {
		this.tokenGenerator = tokenGenerator;
	}

	public TokenStoreService getTokenStoreService() {
		if (tokenStoreService == null) {
			tokenStoreService = TokenStoreServiceHolder.getTokenStoreService();
		}
		return tokenStoreService;
	}

	public TokenGenerator getTokenGenerator() {
		if (tokenGenerator == null) {
			tokenGenerator = new TokenGeneratorImpl();
		}
		return tokenGenerator;
	}

}
